package wrapper;

/**
 * @Author Justin Parker
 * @Date 2024/7/12 0012 16:53
 * @Version 1.0
 *
 * java中有8个基本数据类型，他们是以“值”的形式存在，而非对象
 * 因此8个基本数据类型不具备面向对象的特性，对此java提供了8个包装类
 * 目的是将基本类型以对象形式存在
 *
 * 基本类型                 包装类
 * byte                java.lang.Byte
 * short               java.lang.Short
 * int                 java.lang.Integer
 * long                java.lang.Long
 * float               java.lang.Float
 * double              java.lang.Double
 * char                java.long.Character
 * boolean             java.long.Boolean
 */
public class IntegerDemo01 {
    public static void main(String[] args) {
            int a = 128;    //-128~127之间，那么valueof方法会重用对象
//        Integer i1 =new Integer(a);
//        Integer i2 =new Integer(a);
          Integer i1 =Integer.valueOf(a);
          Integer i2 =Integer.valueOf(a);

        System.out.println(i1 == i2);
        System.out.println(i1.equals(i2));

        //Double 的valueof就没有任何多余效果，就是new,但是我们依然建议使用valueof（不用记哪些包装类有额外功能）
        double d = 123.456;
        Double d1 =Double.valueOf(d);
        Double d2 =Double.valueOf(d);
        System.out.println(d1 == d2);
        System.out.println(d1.equals(d2));

        System.out.println("------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");

        int i = i1.intValue();
        System.out.println(i);
        double d3 = i1.doubleValue();
        System.out.println(d3);
        byte d4 = i1.byteValue();
        System.out.println(d4);

        i = d1.intValue(); //123.456
        System.out.println(i);//123,浮点数转换为整数仍然存在丢失精度
        d3 = d1.doubleValue();
        System.out.println(d3);//123.456
    }
}
